home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Draw / Clipboard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-22  |  6.5 KB  |  248 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        Clipboard.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1992 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* This file contains the code for the document procedure pointers for the DTS.Draw
  12. ** clipboard document.  The clipboard document is simply a modified DTS.Draw document.
  13. ** Many of the main document facilities are removed, since they don't apply to the
  14. ** clipboard.  See ClipboardInitDocument() for a full breakdown of the changes in
  15. ** the document procedures. */
  16.  
  17.  
  18.  
  19. /*****************************************************************************/
  20.  
  21.  
  22.  
  23. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  24. #include "App.Common.h"        /* Get the stuff in common with rez.            */
  25. #include "App.protos.h"        /* Get the prototypes for the application.        */
  26.  
  27. #ifndef __AppMenu__
  28. #include "App.Menu.h"
  29. #endif
  30.  
  31. #ifndef __ERRORS__
  32. #include <Errors.h>
  33. #endif
  34.  
  35. #ifndef __TREEOBJ2__
  36. #include "TreeObj2.h"
  37. #endif
  38.  
  39.  
  40.  
  41. /*****************************************************************************/
  42.  
  43.  
  44.  
  45. WindowPtr    gClipboardWindow;
  46.  
  47. extern RgnHandle    gCursorRgn;
  48. extern CursPtr        gCursorPtr;
  49.  
  50. static OSErr    ClipboardInitContent(FileRecHndl frHndl, WindowPtr window);
  51. static void        ClipboardContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
  52. static Boolean    ClipboardContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough);
  53. static Boolean    ClipboardWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt);
  54.  
  55.  
  56.  
  57. /*****************************************************************************/
  58. /*****************************************************************************/
  59.  
  60.  
  61.  
  62. /* Open an invisible clipboard document/window. */
  63.  
  64. #pragma segment ClipboardDoc
  65. void    OpenClipboard(void)
  66. {
  67.     FileRecHndl    frHndl;
  68.  
  69.     NewDocument(&frHndl, kClipboardFileType, false);
  70.     DoNewWindow(frHndl, &gClipboardWindow, nil, (WindowPtr)-1);
  71. }
  72.  
  73.  
  74.  
  75. /*****************************************************************************/
  76.  
  77.  
  78.  
  79. /* Initialize the clipboard document. */
  80.  
  81. #pragma segment ClipboardDoc
  82. OSErr    ClipboardInitDocument(FileRecHndl frHndl)
  83. {
  84.     OSErr        err;
  85.     FileRecPtr    frPtr;
  86.  
  87.     err = DefaultInitDocument(frHndl, 0, 0, 0);
  88.  
  89.     if (!err) {
  90.         frPtr = *frHndl;
  91.         frPtr->fileState.windowID                = rClipboardWindow;
  92.         frPtr->fileState.calcFrameRgnProc        = nil;
  93.         frPtr->fileState.contentClickProc        = ClipboardContentClick;
  94.         frPtr->fileState.contentKeyProc          = ClipboardContentKey;
  95.         frPtr->fileState.drawFrameProc           = nil;
  96.         frPtr->fileState.freeDocumentProc        = nil;
  97.         frPtr->fileState.freeWindowProc          = nil;
  98.         frPtr->fileState.initContentProc         = ClipboardInitContent;
  99.         frPtr->fileState.readDocumentProc        = nil;
  100.         frPtr->fileState.readDocumentHeaderProc  = nil;
  101.         frPtr->fileState.resizeContentProc       = nil;
  102.         frPtr->fileState.scrollFrameProc         = nil;
  103.         frPtr->fileState.undoFixupProc           = nil;
  104.         frPtr->fileState.windowCursorProc        = ClipboardWindowCursor;
  105.         frPtr->fileState.writeDocumentProc       = nil;
  106.         frPtr->fileState.writeDocumentHeaderProc = nil;
  107.  
  108.         frPtr->fileState.fss.name[0] = 0;        /* Use resource window name. */
  109.         frPtr->fileState.attributes  = kwClipboardWindow;
  110.     }
  111.  
  112.     return(err);
  113. }
  114.  
  115.  
  116.  
  117. /*****************************************************************************/
  118.  
  119.  
  120.  
  121. /* Initialize the clipboard document size.  By waiting this late to state the
  122. ** document size, the window is initially opened to the size described in the
  123. ** 'WIND' resource for the clipboard.  Once the window exists, we can then
  124. ** set the document size to be 7 inches by 10 inches. */
  125.  
  126. #pragma segment ClipboardDoc
  127. static OSErr    ClipboardInitContent(FileRecHndl frHndl, WindowPtr window)
  128. {
  129. #pragma unused (window)
  130.  
  131.     (*frHndl)->d.doc.fhInfo.hDocSize = (7 * 72);
  132.     (*frHndl)->d.doc.fhInfo.vDocSize = (10 * 72);
  133.     return(noErr);
  134. }
  135.  
  136.  
  137.  
  138. /*****************************************************************************/
  139. /*****************************************************************************/
  140.  
  141.  
  142.  
  143. /* Handle only document scrolling for the clipboard. */
  144.  
  145. #pragma segment ClipboardDoc
  146. static void    ClipboardContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
  147. {
  148. #pragma unused (frHndl, firstClick)
  149.  
  150.     IsCtlEvent(window, event, nil, nil);
  151. }
  152.  
  153.  
  154.  
  155. /*****************************************************************************/
  156.  
  157.  
  158.  
  159. /* No keys for the clipboard.  Returning true eats all of the keys, so that
  160. ** they aren't passed on to the next window behind the clipboard. */
  161.  
  162. #pragma segment ClipboardDoc
  163. static Boolean    ClipboardContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough)
  164. {
  165. #pragma unused (window, event, passThrough)
  166.  
  167.     return(true);
  168. }
  169.  
  170.  
  171.  
  172. /*****************************************************************************/
  173.  
  174.  
  175.  
  176. /* Whenever the clipboard is active, just use an arrow cursor. */
  177.  
  178. #pragma segment ClipboardDoc
  179. static Boolean    ClipboardWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt)
  180. {
  181. #pragma unused (frHndl, window, globalPt)
  182.  
  183.     SetCursor(gCursorPtr = &qd.arrow);
  184.     return(true);
  185. }
  186.  
  187.  
  188.  
  189. /*****************************************************************************/
  190. /*****************************************************************************/
  191.  
  192.  
  193.  
  194. /* Handle cut/copy/paste for the clipboard. */
  195.  
  196. #pragma segment ClipboardDoc
  197. void    DoClipboard(FileRecHndl frHndl, short menuItem)
  198. {
  199.     FileRecHndl    frClip;
  200.     TreeObjHndl    root, rootClip, chndl;
  201.     short        cnum;
  202.     WindowPtr    window;
  203.  
  204.     frClip   = (FileRecHndl)GetWRefCon(gClipboardWindow);
  205.     rootClip = (*frClip)->d.doc.root;
  206.     root     = (*frHndl)->d.doc.root;
  207.  
  208.     if (menuItem != iCopy)
  209.         NewDocumentUndo(frHndl);
  210.  
  211.     switch (menuItem) {
  212.         case iCut:
  213.         case iCopy:
  214.             while ((*rootClip)->numChildren) DisposeChild(NO_EDIT, rootClip, 0);
  215.             for (cnum = (*root)->numChildren; cnum;) {
  216.                 chndl = GetChildHndl(root, --cnum);
  217.                 if (mDerefCommon(chndl)->selected) {
  218.                     CopyChild(NO_EDIT, root, cnum, rootClip, 0, true);
  219.                     mDerefCommon(GetChildHndl(rootClip, 0))->selected = false;
  220.                     mDerefRoot(rootClip)->numSelected = 0;
  221.                 }
  222.             }
  223.             if (((WindowPeek)gClipboardWindow)->visible) {
  224.                 BeginContent(gClipboardWindow);
  225.                 DoImageDocument(frClip);
  226.                 EndContent(gClipboardWindow);
  227.             }
  228.             if (menuItem == iCut)
  229.                 DoDelete(frHndl);
  230.             break;
  231.         case iPaste:
  232.             DoTreeSelect(root, SELECTOFF);
  233.             for (cnum = (*rootClip)->numChildren; cnum;) {
  234.                 chndl = GetChildHndl(rootClip, --cnum);
  235.                 CopyChild(CLIPBOARD_EDIT, rootClip, cnum, root, 0, true);
  236.             }
  237.             window = (*frHndl)->fileState.window;
  238.             BeginContent(window);
  239.             DoImageDocument(frHndl);
  240.             EndContent(window);
  241.             break;
  242.     }
  243. }
  244.  
  245.  
  246.  
  247.  
  248.